// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_int_from_decimal32_9_1") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_int_from_decimal32_9_1_0_nullable;"
    sql "create table test_cast_to_int_from_decimal32_9_1_0_nullable(f1 int, f2 decimalv3(9, 1)) properties('replication_num'='1');"
    sql """insert into test_cast_to_int_from_decimal32_9_1_0_nullable values (0, "0.0"),(1, "0.0"),(2, "0.1"),(3, "-0.1"),(4, "0.9"),(5, "-0.9"),(6, "0.9"),(7, "-0.9"),(8, "0.8"),(9, "-0.8"),(10, "0.0"),(11, "0.0"),(12, "0.9"),(13, "-0.9"),(14, "0.8"),(15, "-0.8"),(16, "1.0"),(17, "-1.0"),(18, "1.1"),(19, "-1.1"),
      (20, "1.9"),(21, "-1.9"),(22, "1.9"),(23, "-1.9"),(24, "1.8"),(25, "-1.8"),(26, "1.0"),(27, "-1.0"),(28, "1.9"),(29, "-1.9"),(30, "1.8"),(31, "-1.8"),(32, "9.0"),(33, "-9.0"),(34, "9.1"),(35, "-9.1"),(36, "9.9"),(37, "-9.9"),(38, "9.9"),(39, "-9.9"),
      (40, "9.8"),(41, "-9.8"),(42, "9.0"),(43, "-9.0"),(44, "9.9"),(45, "-9.9"),(46, "9.8"),(47, "-9.8"),(48, "99999999.0"),(49, "-99999999.0"),(50, "99999999.1"),(51, "-99999999.1"),(52, "99999999.9"),(53, "-99999999.9"),(54, "99999999.9"),(55, "-99999999.9"),(56, "99999999.8"),(57, "-99999999.8"),(58, "99999999.0"),(59, "-99999999.0"),
      (60, "99999999.9"),(61, "-99999999.9"),(62, "99999999.8"),(63, "-99999999.8"),(64, "99999998.0"),(65, "-99999998.0"),(66, "99999998.1"),(67, "-99999998.1"),(68, "99999998.9"),(69, "-99999998.9"),(70, "99999998.9"),(71, "-99999998.9"),(72, "99999998.8"),(73, "-99999998.8"),(74, "99999998.0"),(75, "-99999998.0"),(76, "99999998.9"),(77, "-99999998.9"),(78, "99999998.8"),(79, "-99999998.8"),
      (80, "9999999.0"),(81, "-9999999.0"),(82, "9999999.1"),(83, "-9999999.1"),(84, "9999999.9"),(85, "-9999999.9"),(86, "9999999.9"),(87, "-9999999.9"),(88, "9999999.8"),(89, "-9999999.8"),(90, "9999999.0"),(91, "-9999999.0"),(92, "9999999.9"),(93, "-9999999.9"),(94, "9999999.8"),(95, "-9999999.8"),(96, "90000000.0"),(97, "-90000000.0"),(98, "90000000.1"),(99, "-90000000.1"),
      (100, "90000000.9"),(101, "-90000000.9"),(102, "90000000.9"),(103, "-90000000.9"),(104, "90000000.8"),(105, "-90000000.8"),(106, "90000000.0"),(107, "-90000000.0"),(108, "90000000.9"),(109, "-90000000.9"),(110, "90000000.8"),(111, "-90000000.8"),(112, "90000001.0"),(113, "-90000001.0"),(114, "90000001.1"),(115, "-90000001.1"),(116, "90000001.9"),(117, "-90000001.9"),(118, "90000001.9"),(119, "-90000001.9"),
      (120, "90000001.8"),(121, "-90000001.8"),(122, "90000001.0"),(123, "-90000001.0"),(124, "90000001.9"),(125, "-90000001.9"),(126, "90000001.8"),(127, "-90000001.8")
      ,(128, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as int) from test_cast_to_int_from_decimal32_9_1_0_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as int) from test_cast_to_int_from_decimal32_9_1_0_nullable order by 1;'

    sql "drop table if exists test_cast_to_int_from_decimal32_9_1_0_not_nullable;"
    sql "create table test_cast_to_int_from_decimal32_9_1_0_not_nullable(f1 int, f2 decimalv3(9, 1)) properties('replication_num'='1');"
    sql """insert into test_cast_to_int_from_decimal32_9_1_0_not_nullable values (0, "0.0"),(1, "0.0"),(2, "0.1"),(3, "-0.1"),(4, "0.9"),(5, "-0.9"),(6, "0.9"),(7, "-0.9"),(8, "0.8"),(9, "-0.8"),(10, "0.0"),(11, "0.0"),(12, "0.9"),(13, "-0.9"),(14, "0.8"),(15, "-0.8"),(16, "1.0"),(17, "-1.0"),(18, "1.1"),(19, "-1.1"),
      (20, "1.9"),(21, "-1.9"),(22, "1.9"),(23, "-1.9"),(24, "1.8"),(25, "-1.8"),(26, "1.0"),(27, "-1.0"),(28, "1.9"),(29, "-1.9"),(30, "1.8"),(31, "-1.8"),(32, "9.0"),(33, "-9.0"),(34, "9.1"),(35, "-9.1"),(36, "9.9"),(37, "-9.9"),(38, "9.9"),(39, "-9.9"),
      (40, "9.8"),(41, "-9.8"),(42, "9.0"),(43, "-9.0"),(44, "9.9"),(45, "-9.9"),(46, "9.8"),(47, "-9.8"),(48, "99999999.0"),(49, "-99999999.0"),(50, "99999999.1"),(51, "-99999999.1"),(52, "99999999.9"),(53, "-99999999.9"),(54, "99999999.9"),(55, "-99999999.9"),(56, "99999999.8"),(57, "-99999999.8"),(58, "99999999.0"),(59, "-99999999.0"),
      (60, "99999999.9"),(61, "-99999999.9"),(62, "99999999.8"),(63, "-99999999.8"),(64, "99999998.0"),(65, "-99999998.0"),(66, "99999998.1"),(67, "-99999998.1"),(68, "99999998.9"),(69, "-99999998.9"),(70, "99999998.9"),(71, "-99999998.9"),(72, "99999998.8"),(73, "-99999998.8"),(74, "99999998.0"),(75, "-99999998.0"),(76, "99999998.9"),(77, "-99999998.9"),(78, "99999998.8"),(79, "-99999998.8"),
      (80, "9999999.0"),(81, "-9999999.0"),(82, "9999999.1"),(83, "-9999999.1"),(84, "9999999.9"),(85, "-9999999.9"),(86, "9999999.9"),(87, "-9999999.9"),(88, "9999999.8"),(89, "-9999999.8"),(90, "9999999.0"),(91, "-9999999.0"),(92, "9999999.9"),(93, "-9999999.9"),(94, "9999999.8"),(95, "-9999999.8"),(96, "90000000.0"),(97, "-90000000.0"),(98, "90000000.1"),(99, "-90000000.1"),
      (100, "90000000.9"),(101, "-90000000.9"),(102, "90000000.9"),(103, "-90000000.9"),(104, "90000000.8"),(105, "-90000000.8"),(106, "90000000.0"),(107, "-90000000.0"),(108, "90000000.9"),(109, "-90000000.9"),(110, "90000000.8"),(111, "-90000000.8"),(112, "90000001.0"),(113, "-90000001.0"),(114, "90000001.1"),(115, "-90000001.1"),(116, "90000001.9"),(117, "-90000001.9"),(118, "90000001.9"),(119, "-90000001.9"),
      (120, "90000001.8"),(121, "-90000001.8"),(122, "90000001.0"),(123, "-90000001.0"),(124, "90000001.9"),(125, "-90000001.9"),(126, "90000001.8"),(127, "-90000001.8");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as int) from test_cast_to_int_from_decimal32_9_1_0_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as int) from test_cast_to_int_from_decimal32_9_1_0_not_nullable order by 1;'

}